package cn.innosmart.aq.util;

import android.content.Context;
import android.graphics.Bitmap;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.NetworkError;
import com.android.volley.NoConnectionError;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.ServerError;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.JsonRequest;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import cn.innosmart.aq.BuildConfig;
import cn.innosmart.aq.R;
import cn.innosmart.aq.application.AQApplication;
import cn.innosmart.aq.cache.LruImageCache;

/**
 * Created by David on 2015/7/22.
 */
public class NetworkInteractUtil {
    public final String LOGIN = "LOGIN";
    public final String MODIFYNICKNAME = "MODIFYNICKNAME";
    public final String MODIFYPASSWORD = "MODIFYPASSWORD";
    public final String HEADICON = "HEADICON";
    public final String BANNER = "BANNER";
    public final String SYNCADDBOX = "SYNCADDBOX";
    public final String SYNCMODIFYBOX = "SYNCMODIFYBOX";
    public final String SYNCREMOVEBOX = "SYNCREMOVEBOX";
    public final String OTHERHISTORYDATA = "OTHERHISTORYDATA";
    public final String SWITCHHISTORYDATA = "SWITCHHISTORYDATA";
    public final String WATERLEVERHISTORYDATA = "WATERLEVERHISTORYDATA";
    public final String FEEDERHISTORYDATA = "FEEDERHISTORYDATA";
    public final String REGIST = "REGIST";
    public final String RESETPASSWORD = "RESETPASSWORD";
    public final String REGISTVERIFY = "REGISTVERIFY";
    public final String FINDPASSWORDVERIFY = "FINDPASSWORDVERIFY";
    public final String UPDATELOCATION = "UPDATELOCATION";
    public final String NEARBY = "NEARBY";
    public final String ADDFRIEND = "ADDFRIEND";
    public final String GETFRIEND = "GETFRIEND";
    public final String REMOVEFRIEND = "REMOVEFRIEND";
    public final String GETWORKLOGTEMP = "GETWORKLOGTEMP";
    public final String ADDWORKLOGTEMP = "ADDWORKLOGTEMP";
    public final String REMOVEWORKLOGTEMP = "REMOVEWORKLOGTEMP";
    public final String ADDWORKLOG = "ADDWORKLOG";
    public final String GETWORKLOG = "GETWORKLOG";
    public final String ADDEMPLOYEE = "ADDEMPLOYEE";
    public final String REMOVEEMPLOYEE = "REMOVEEMPLOYEE";
    public final String GETEMPLOYEEASSIGNED = "GETEMPLOYEEASSIGNED";
    public final String ASSIGNTO = "ASSIGNTO";
    public final String UPDATEASSIGNTO = "UPDATEASSIGNTO";
    public final String GETNEWORDERID = "GETNEWORDERID";

    private INetworkInteractUtil iInteractUtil;
    private ArrayList<String> flags;
    private Context mContext;
    private JsonRequest loginRequest;
    private JsonObjectRequest modifyNickNameRequest;
    private JsonObjectRequest modifyPasswordRequest;
    private ImageRequest headIconRequest;
    private StringRequest getBannerJsonRequest;
    private JsonObjectRequest syncAddBoxRequest;
    private JsonObjectRequest syncModifyBoxRequest;
    private JsonObjectRequest syncRemoveBoxRequest;
    private boolean isChecked = false;
    private JsonObjectRequest otherHistoryRequest;
    private JsonArrayRequest switchHistoryRequest;
    private JsonArrayRequest waterLeverHistoryRequest;
    private JsonArrayRequest feederHistoryRequest;
    private JsonObjectRequest registRequest;
    private JsonObjectRequest resetPasswordRequest;
    private JsonObjectRequest registerVerifyRequest;
    private JsonObjectRequest findPasswordVerifyRequest;
    private JsonObjectRequest updateLocationRequest;
    private JsonObjectRequest getNearByRequest;
    private JsonObjectRequest addFriendRequest;
    private JsonObjectRequest getFriendRequest;
    private JsonObjectRequest removeFriendRequest;
    private JsonArrayRequest getWorkLogTempRequest;
    private JsonObjectRequest addWorkLogTemp;
    private JsonObjectRequest addWorkLog;
    private JsonObjectRequest removeWorkLogTemp;
    private JsonArrayRequest getWorkLogRequest;

    private JsonObjectRequest syncGetNewOrderIDRequest;

    /**
     * Add Employee
     *
     * @param jsonParam
     */
    private JsonObjectRequest addEmployeeRequest;
    /**
     * removeEmployee
     *
     * @param jsonParam
     */
    private JsonObjectRequest removeEmployeeRequest;
    /**
     * getEmployeeAssigned
     *
     * @param jsonParam
     */
    private JsonObjectRequest getEmployeeAssignedRequest;
    /**
     * assignTo
     *
     * @param jsonParam
     */
    private JsonObjectRequest assignToRequest;
    /**
     * updateAssignTo
     *
     * @param jsonParam
     */
    private JsonObjectRequest updateAssignToRequest;

    /**
     * 构造函数
     *
     * @param iInteractUtil 回调函数
     */
    public NetworkInteractUtil(INetworkInteractUtil iInteractUtil) {
        this.iInteractUtil = iInteractUtil;
        flags = new ArrayList<String>();
        mContext = AQApplication.getInstance();
    }

    /**
     * 添加工作日志
     *
     * @param jsonParam
     */
    public void addWorkLog(JSONObject jsonParam) {
        flags.add(ADDWORKLOG);
        try {
            jsonParam.put("creator", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        System.out.println("Post=" + jsonParam.toString());
        /**
         * {"uname":"admin2","device":
         * {"did":"SUCU-000001-ABCEF","username":"admin","password":"123456","name":"sncu"}}
         */
        addWorkLog = new JsonObjectRequest(Request.Method.POST, SystemConstant.add_work_log, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(ADDWORKLOG);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, ADDWORKLOG, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, ADDWORKLOG, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(addWorkLog);
    }

    /**
     * 添加工作日志模板
     *
     * @param jsonParam
     */
    public void addWorkLogTemp(JSONObject jsonParam) {
        flags.add(ADDWORKLOGTEMP);
        try {
            jsonParam.put("creator", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /**
         * {"uname":"admin2","device":
         * {"did":"SUCU-000001-ABCEF","username":"admin","password":"123456","name":"sncu"}}
         */
        addWorkLogTemp = new JsonObjectRequest(Request.Method.POST, SystemConstant.add_work_log_temp, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(ADDWORKLOGTEMP);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, ADDWORKLOGTEMP, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, ADDWORKLOGTEMP, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(addWorkLogTemp);
    }

    /**
     * 删除工作日志模板
     *
     * @param jsonParam
     */
    public void removeWorkLogTemp(JSONObject jsonParam) {
        flags.add(REMOVEWORKLOGTEMP);
//        try {
//            jsonParam.put("creator", SharedUtil.getInstance().readUserId());
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
        /**
         * {"uname":"admin2","device":
         * {"did":"SUCU-000001-ABCEF","username":"admin","password":"123456","name":"sncu"}}
         */
        removeWorkLogTemp = new JsonObjectRequest(Request.Method.POST, SystemConstant.delete_work_log_temp, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        flags.remove(REMOVEWORKLOGTEMP);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, REMOVEWORKLOGTEMP, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, REMOVEWORKLOGTEMP, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(removeWorkLogTemp);
    }

    /**
     * 获取工作日志
     *
     * @param templateId
     */
    public void getWorkLog(String templateId) {
        System.out.println("getWorkLog");
        flags.add(GETWORKLOG);
        String url = String.format(SystemConstant.get_worklog_url, templateId);
        System.out.println("url=" + url);
        getWorkLogRequest = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                try {
                    flags.remove(GETWORKLOG);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(0, GETWORKLOG, response);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(0);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                iInteractUtil.onNetworkInteractOver(-1, GETWORKLOG, new JSONArray());
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(getWorkLogRequest);
    }

    /**
     * 获取工作日志模板
     */
    public void getWorkLogTemp() {
        System.out.println("getWorkLogTemp");
        flags.add(GETWORKLOGTEMP);
        String url = String.format(SystemConstant.get_worklog_temp_url, SharedUtil.getInstance().readUserId());
        System.out.println("url=" + url);
        getWorkLogTempRequest = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                try {
                    flags.remove(GETWORKLOGTEMP);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(0, GETWORKLOGTEMP, response);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(0);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                iInteractUtil.onNetworkInteractOver(-1, GETWORKLOGTEMP, new JSONArray());
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(getWorkLogTempRequest);
    }

    //连接登录方法
    public void login(final String username, final String password, boolean hublist) {
        System.out.println("login");
        flags.add(LOGIN);
        /**
         * 设置Headers
         */
        JSONObject jsonParams = new JSONObject();
        try {
            jsonParams.put("username", username);
            jsonParams.put("password", password);
            jsonParams.put("hublist", hublist);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /**
         * 设置登录请求   注释掉了IM登陆部分 2015 11 16
         */
        loginRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.login_url, jsonParams, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                System.out.println("response=" + response.toString());
                try {
                    int ret = response.getInt("code");
                    if (ret == 0) {
                        //记录登录日志
                        System.out.println("username=" + username + ",password=" + password);
                        SharedUtil.getInstance().writeLoginInfo(username, String.valueOf(password));
                        JSONObject login = SharedUtil.getInstance().readLoginInfo();
                        System.out.println("loginssss=" + login.toString());
                        //登录成功,修改登录信息
                        SystemConstant.username = username;
                        //记录Token信息
                        String session_token = response.getString("token");
                        SharedUtil.getInstance().writeLoginSession(session_token);
                        SystemConstant.session_token = session_token;
                        String userInfo = response.getJSONObject("userinfo").toString();
                        String id = response.getJSONObject("userinfo").getString("id");
                        String nickName = response.getJSONObject("userinfo").getString("nickname");
                        SystemConstant.nickname = nickName;
                        SystemConstant.openid = response.getString("openid");
                        System.out.println("nickName=" + SystemConstant.nickname);
                        System.out.println("id=" + id);
//                        AQApplication.getInstance().initIM(id, nickName);
                        SharedUtil.getInstance().writeUserInfo(userInfo);
                        //记录Box信息到本地
                        JSONArray gatewayInfo = response.getJSONObject("userinfo").getJSONArray("devices");
                        JSONArray assignedGatewayInfo = response.getJSONObject("userinfo").getJSONArray("assigned");
                        JSONObject jsonGateway = null;
                        for (int i = 0; i < assignedGatewayInfo.length(); i++) {
                            jsonGateway = assignedGatewayInfo.getJSONObject(i);
                            gatewayInfo.put(jsonGateway);
                        }
                        //清除本地Gateway数据
                        SharedUtil.getInstance().clearLocalGatewayInfo();
                        //[{"owner":"55dbfd4f6b60b4cb101d9488","did":"AQ01JKTMGR000003","username":"admin","password":"123456","alias":"003","assignTo":[],"_id":"55e3fd8555d0bdf833a181ae"}]
                        SharedUtil.getInstance().writeGatewayInfo(gatewayInfo.toString());
                        //将Box信息更新到内存
                        if (SystemConstant.boxBeanList != null)
                            SystemConstant.boxBeanList.clear();
                        SystemConstant.boxBeanList = GatewayListUtil.getInstance().analyseGatewayInfo(gatewayInfo.toString());
                        //修改登录状态
                        SystemConstant.loginStatus = SystemConstant.Online;
                    } else {
                        //登录失败处理
                        SystemConstant.loginStatus = SystemConstant.Offline;
                    }
                    flags.remove(LOGIN);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(ret, LOGIN, null);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(0);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                error.printStackTrace();
                if (error instanceof NetworkError) {
                    flags.remove(LOGIN);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(-2, LOGIN, mContext.getString(R.string.network_error));
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(-1);
                        }
                    }
                } else if (error instanceof ServerError) {
                    flags.remove(LOGIN);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(-3, LOGIN, "");
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(-1);
                        }
                    }
                } else if (error instanceof AuthFailureError) {
                    flags.remove(LOGIN);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(-1, LOGIN, null);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(-1);
                        }
                    }
                } else if (error instanceof ParseError) {
                    flags.remove(LOGIN);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(-1, LOGIN, null);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(-1);
                        }
                    }
                } else if (error instanceof NoConnectionError) {
                    flags.remove(LOGIN);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(-2, LOGIN, mContext.getString(R.string.network_error));
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(-1);
                        }
                    }
                } else if (error instanceof TimeoutError) {
                    flags.remove(LOGIN);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(-1, LOGIN, null);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(-1);
                        }
                    }
                } else {
                }
            }
        });
        //设置5秒超时
        loginRequest.setRetryPolicy(new DefaultRetryPolicy(0, 0, 1.0f));
        AQApplication.getInstance().mQueue.add(loginRequest);
    }

    //获取头像方法
    public void getHeadIcon(String uid) {
        flags.add(HEADICON);
        String imageUrl = "http://bbs.innosmart.cn/uc_server/avatar.php?uid=%@&size=small".replace("%@", uid);
        headIconRequest = new ImageRequest(imageUrl, new Response.Listener<Bitmap>() {
            @Override
            public void onResponse(Bitmap response) {
                ImageComTools.saveBitmapByName(response, SystemConstant.HEAD_ICON, mContext);
                flags.remove(HEADICON);
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(0, HEADICON, null);
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
            }
        });
        AQApplication.getInstance().mQueue.add(headIconRequest);
    }

    /**
     * 修改昵称
     *
     * @param jsonParam
     */
    public void syncModifyNickName(JSONObject jsonParam) {
        flags.add(MODIFYNICKNAME);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /**
         * {"uname":"admin2","device":
         * {"did":"SUCU-000001-ABCEF","username":"admin","password":"123456","name":"sncu"}}
         */
        modifyNickNameRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.modifyNickName_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(MODIFYNICKNAME);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, MODIFYNICKNAME, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, MODIFYNICKNAME, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(modifyNickNameRequest);
    }

    /**
     * 修改密码
     *
     * @param jsonParam
     */
    public void syncModifyPassword(JSONObject jsonParam) {
        flags.add(MODIFYPASSWORD);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /**
         * {"uname":"admin2","device":
         * {"did":"SUCU-000001-ABCEF","username":"admin","password":"123456","name":"sncu"}}
         */
        modifyPasswordRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.modifyPassword_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(MODIFYPASSWORD);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, MODIFYPASSWORD, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, MODIFYPASSWORD, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(modifyPasswordRequest);
    }

    public void syncModifyPassword(JSONObject jsonParam, final INetworkInteractUtil callback) {
        flags.add(MODIFYPASSWORD);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /**
         * {"uname":"admin2","device":
         * {"did":"SUCU-000001-ABCEF","username":"admin","password":"123456","name":"sncu"}}
         */
        modifyPasswordRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.modifyPassword_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(MODIFYPASSWORD);
                        if (callback != null) {
                            callback.onNetworkInteractOver(0, MODIFYPASSWORD, response);
                            if (flags.size() == 0 && isChecked) {
                                callback.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    callback.onNetworkInteractOver(-1, MODIFYPASSWORD, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        callback.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(modifyPasswordRequest);
    }

    /**
     * 获取Banner信息
     */
    public void getBanner() {
        flags.add(BANNER);
        System.out.println("getBanner");
        getBannerJsonRequest = new StringRequest(BuildConfig.BANNERURL,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        //此处注意将获得json字串去除回车，否则会导致比对失败，永远从服务器获取图片
                        response = response.replaceAll("\r|\n", "");
                        String bannerinfo = SharedUtil.getInstance().readBannerInfo();
                        //此处判断依据是版本号不同（目前没加上，只是简单比对json字串是否相等）
                        if (!response.equals(bannerinfo)) {
                            SharedUtil.getInstance().writeBannerInfo(response);
                            LruImageCache.instance().forceUpdate = true;
                        }
                        flags.remove(BANNER);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, BANNER, null);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("eror=" + error.toString());
                flags.remove(BANNER);
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, BANNER, null);
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(-1);
                    }
                }
            }
        });
        //设置5秒超时时间
        getBannerJsonRequest.setRetryPolicy(new DefaultRetryPolicy(0, 0, 1.0f));
        AQApplication.getInstance().mQueue.add(getBannerJsonRequest);
    }

    /**
     * 添加Box
     *
     * @param jsonParam
     */
    public void syncAddBox(JSONObject jsonParam) {
        System.out.println("NetworkInteractUtil syncAddBox");
        flags.add(SYNCADDBOX);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /**
         * {"uname":"admin2","device":
         * {"did":"SUCU-000001-ABCEF","username":"admin","password":"123456","name":"sncu"}}
         */
        syncAddBoxRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.addBox_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("NetworkInteractUtil syncAddBox has response");

                        flags.remove(SYNCADDBOX);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, SYNCADDBOX, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, SYNCADDBOX, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }

            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(syncAddBoxRequest);
    }

    /**
     * 修改Box
     *
     * @param uid
     * @param jsonParam
     */
    public void syncModifyBox(String uid, JSONObject jsonParam) {
        flags.add(SYNCMODIFYBOX);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /**
         * {"uname":"admin2","device":
         * {"did":"SUCU-000001-ABCEF","username":"admin","password":"123456","name":"sncu"}}
         */
        syncModifyBoxRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.modifyBox_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(SYNCMODIFYBOX);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, SYNCMODIFYBOX, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, SYNCMODIFYBOX, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(syncModifyBoxRequest);
    }

    /**
     * 删除Box
     *
     * @param hubId
     * @param jsonParam
     */
    public void syncRemoveBox(String hubId, JSONObject jsonParam) {
        flags.add(SYNCREMOVEBOX);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
            jsonParam.put("id", hubId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        /**
         * {"uname":"admin2","device":
         *
         */
        syncRemoveBoxRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.removeBox_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(SYNCREMOVEBOX);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, SYNCREMOVEBOX, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, SYNCREMOVEBOX, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(syncRemoveBoxRequest);
    }

    public void checkFlags() {
        isChecked = true;
    }

    //获取图表类设备的历史数据
    public void getOtherHistoryData(final String device_id, final String did, String startTime, String endTime, String average) {
        System.out.println("history");
        flags.add(OTHERHISTORYDATA);
        JSONObject jsonParams = new JSONObject();
        try {
            jsonParams.put("start", startTime);
            jsonParams.put("end", endTime);
            jsonParams.put("avg", average);
            jsonParams.put("id", device_id);
            jsonParams.put("did", did);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        System.out.println("jsonparam=" + jsonParams.toString());
        /**
         * "{\"start\":\"%@\",\"end\":\"%@\",\"avg\":\"%@\",\"id\":\"%@\",\"did\":\"%@\"}"
         */
        otherHistoryRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.getChartUrl, jsonParams, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    System.out.println(response.toString());
                    flags.remove(OTHERHISTORYDATA);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(0, OTHERHISTORYDATA, response);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(0);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                iInteractUtil.onNetworkInteractOver(-1, OTHERHISTORYDATA, new JSONArray());
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(otherHistoryRequest);
    }

    //获取插座类历史数据
    public void getSwitchHistoryData(final String device_id, final String did, String startTime, String endTime) {
        System.out.println("history");
        flags.add(SWITCHHISTORYDATA);
        String url = String.format(SystemConstant.switch_history_url, startTime, endTime, device_id, did);
        System.out.println("url=" + url);
        /**
         * 设置登录请求
         */
        switchHistoryRequest = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                try {
                    flags.remove(SWITCHHISTORYDATA);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(0, SWITCHHISTORYDATA, response);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(0);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                iInteractUtil.onNetworkInteractOver(-1, SWITCHHISTORYDATA, new JSONArray());
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(switchHistoryRequest);
    }

    /**
     * 获取水位历史数据
     *
     * @param device_id
     * @param did
     * @param startTime
     * @param endTime
     */
    public void getWaterLeverHistoryData(final String device_id, final String did, String startTime, String endTime) {
        System.out.println("history");
        flags.add(WATERLEVERHISTORYDATA);
        String url = String.format(SystemConstant.water_lever_history_url, startTime, endTime, device_id, did);
        System.out.println("url=" + url);
        waterLeverHistoryRequest = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                try {
                    flags.remove(WATERLEVERHISTORYDATA);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(0, WATERLEVERHISTORYDATA, response);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(0);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                iInteractUtil.onNetworkInteractOver(-1, WATERLEVERHISTORYDATA, new JSONArray());
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(waterLeverHistoryRequest);
    }

    /**
     * 获取喂食历史数据
     *
     * @param device_id
     * @param did
     * @param startTime
     * @param endTime
     */
    public void getFeederHistoryData(final String device_id, final String did, String startTime, String endTime) {
        System.out.println("history");
        flags.add(FEEDERHISTORYDATA);
        String url = String.format(SystemConstant.feeder_history_url, startTime, endTime, device_id, did);
        System.out.println("url=" + url);
        feederHistoryRequest = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                try {
                    flags.remove(FEEDERHISTORYDATA);
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(0, FEEDERHISTORYDATA, response);
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(0);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                iInteractUtil.onNetworkInteractOver(-1, FEEDERHISTORYDATA, new JSONArray());
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(feederHistoryRequest);
    }

    //注册方法
    public void regist(String username, final String password, String nickname, String verification_code) {
        System.out.println("regist=" + username + ",Password=" + password + ",nickname=" + nickname + ",verif=" + verification_code);
        flags.add(REGIST);
        JSONObject params = new JSONObject();
        try {
            params.put("username", username);
            params.put("password", password);
            params.put("nickname", nickname);
            params.put("VerificationCode", verification_code);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        registRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.regist_url, params, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                System.out.println("respones=" + response.toString());
                flags.remove(REGIST);
                int resultCode = -1;
                try {
                    resultCode = response.getInt("code");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                switch (resultCode) {
                    case 0:
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, REGIST, "");
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                    case 1:
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, REGIST, mContext.getString(R.string.username_has_been_used));
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                    default:
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(-1, REGIST, mContext.getString(R.string.regist_failed));
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;

                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, REGIST, mContext.getString(R.string.regist_failed_check_network));
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
                return headers;
            }
        };
        AQApplication.getInstance().mQueue.add(registRequest);
    }

    //FindPassword
    public void findPasswordVerify(String phone) {

        flags.add(FINDPASSWORDVERIFY);
        JSONObject params = new JSONObject();
        if (SystemConstant.LOCAL_MODE == SystemConstant.MODE_CH) {
            phone = "+086" + phone;
        } else if (SystemConstant.LOCAL_MODE == SystemConstant.MODE_TW) {
            phone = "+886" + phone;
        }
        try {
            params.put("phone", phone);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        System.out.println("FINDPASSWORDVERIFY=" + phone);
        findPasswordVerifyRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.findPasswird_verify, params, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                System.out.println("respones=" + response.toString());
                flags.remove(FINDPASSWORDVERIFY);
                int resultCode = -1;
                int verification_code = -1;
                try {
                    resultCode = response.getInt("code");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    verification_code = response.getInt("verification_code");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                switch (resultCode) {
                    case 0:
                        //成功
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, FINDPASSWORDVERIFY, response.toString());
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                    case 1:
                        //账号不存在
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, FINDPASSWORDVERIFY, mContext.getString(R.string.count_is_not_exist));
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                    case 2:
                        //60s不要重复验证
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, FINDPASSWORDVERIFY, mContext.getString(R.string.wait_sixty_second));
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                    default:
                        //验证失败
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(-1, FINDPASSWORDVERIFY, mContext.getString(R.string.verify_failed));
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, FINDPASSWORDVERIFY, mContext.getString(R.string.regist_failed_check_network));
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
                return headers;
            }
        };
        AQApplication.getInstance().mQueue.add(findPasswordVerifyRequest);
    }

    /**
     * 重置密码
     *
     * @param username
     * @param password
     * @param verification_code
     */
    public void resetPassword(String username, final String password, String verification_code) {
        System.out.println("resetPassword   username=" + username + ",Password=" + password + ",verif=" + verification_code);
        flags.add(RESETPASSWORD);
        JSONObject params = new JSONObject();
        try {
            params.put("username", username);
            params.put("password", password);
            params.put("VerificationCode", verification_code);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        resetPasswordRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.resetPassword_url, params, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                System.out.println("respones=" + response.toString());
                flags.remove(RESETPASSWORD);
                int resultCode = -1;
                try {
                    resultCode = response.getInt("code");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                switch (resultCode) {
                    case 0:
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, RESETPASSWORD, "");
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                    default:
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(-1, RESETPASSWORD, mContext.getString(R.string.reset_password_failed));
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;

                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                    if (iInteractUtil != null) {
                        iInteractUtil.onNetworkInteractOver(-1, RESETPASSWORD, mContext.getString(R.string.reset_password_failed_check_network));
                        if (flags.size() == 0 && isChecked) {
                            iInteractUtil.onNetworkInteractAllOver(0);
                        }
                        return;
                    }
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, RESETPASSWORD, mContext.getString(R.string.reset_password_failed));
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
                return headers;
            }
        };
        AQApplication.getInstance().mQueue.add(resetPasswordRequest);
    }

    /**
     * 注册验证
     *
     * @param phone
     */
    public void registVerify(String phone) {
        System.out.println("REGISTVERIFY");
        flags.add(REGISTVERIFY);
        JSONObject params = new JSONObject();
        //根据版本 在前面加上相应的前缀
        try {
            params.put("phone", phone);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        System.out.println("REGISTVERIFY=" + phone);
        registerVerifyRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.registverify_url, params, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                System.out.println("respones=" + response.toString());
                flags.remove(REGISTVERIFY);
                int resultCode = -1;
                int verification_code = -1;
                try {
                    resultCode = response.getInt("code");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    verification_code = response.getInt("verification_code");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                switch (resultCode) {
                    case 0:
                        //成功
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, REGISTVERIFY, response.toString());
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                    case 1:
                        //账号已注册
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, REGISTVERIFY, mContext.getString(R.string.tel_had_been_regist));
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                    case 2:
                        //等待60s再验证
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, REGISTVERIFY, mContext.getString(R.string.wait_sixty_second));
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                    default:
                        //验证失败
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(-1, REGISTVERIFY, mContext.getString(R.string.verify_failed));
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                        break;
                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, REGISTVERIFY, mContext.getString(R.string.regist_failed_check_network));
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
                return headers;
            }
        };
        AQApplication.getInstance().mQueue.add(registerVerifyRequest);
    }

    //{ "userid":userid ,"location":{"latitude":11,"longitude":111}}

    /**
     * 更新位置信息
     *
     * @param jsonParam
     */
    public void updateLocation(JSONObject jsonParam) {
        System.out.println("updateLocation");
        flags.add(UPDATELOCATION);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        updateLocationRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.updateLocation_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(UPDATELOCATION);
                        try {
                            int ret = response.getInt("code");
                            if (iInteractUtil != null) {
                                iInteractUtil.onNetworkInteractOver(ret, UPDATELOCATION, response);
                                if (flags.size() == 0 && isChecked) {
                                    iInteractUtil.onNetworkInteractAllOver(0);
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, UPDATELOCATION, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(updateLocationRequest);
    }

    /**
     * 获取附近的人的方法
     *
     * @param jsonParam
     */
    public void getNearBy(JSONObject jsonParam) {
        System.out.println("updateLocation");
        flags.add(NEARBY);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        getNearByRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.nearByPeople_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(NEARBY);
                        try {
                            int ret = response.getInt("code");
                            if (iInteractUtil != null) {
                                iInteractUtil.onNetworkInteractOver(ret, NEARBY, response);
                                if (flags.size() == 0 && isChecked) {
                                    iInteractUtil.onNetworkInteractAllOver(0);
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, NEARBY, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(getNearByRequest);
    }

    /**
     * 添加朋友
     *
     * @param jsonParam
     */
    public void addFriend(final JSONObject jsonParam) {
        System.out.println("addFriend");
        flags.add(ADDFRIEND);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addFriendRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.addFriend_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(ADDFRIEND);
                        try {
                            int ret = response.getInt("code");
                            response.put("result", jsonParam);
                            if (iInteractUtil != null) {
                                iInteractUtil.onNetworkInteractOver(ret, ADDFRIEND, response);
                                if (flags.size() == 0 && isChecked) {
                                    iInteractUtil.onNetworkInteractAllOver(0);
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, ADDFRIEND, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(addFriendRequest);
    }

    /**
     * 获得朋友列表
     *
     * @param jsonParam
     */
    public void getFriends(JSONObject jsonParam) {
        System.out.println("getFriend");
        flags.add(GETFRIEND);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        getFriendRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.getFriend_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(GETFRIEND);
                        try {
                            int ret = response.getInt("code");
                            if (iInteractUtil != null) {
                                iInteractUtil.onNetworkInteractOver(ret, GETFRIEND, response);
                                if (flags.size() == 0 && isChecked) {
                                    iInteractUtil.onNetworkInteractAllOver(0);
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, GETFRIEND, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(getFriendRequest);
    }

    /**
     * 删除朋友
     *
     * @param jsonParam
     */
    public void removeFriend(final JSONObject jsonParam) {
        System.out.println("removeFriend");
        flags.add(REMOVEFRIEND);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        removeFriendRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.removeFriend_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("response=" + response.toString());
                        flags.remove(REMOVEFRIEND);
                        try {
                            int ret = response.getInt("code");
                            response.put("result", jsonParam);
                            if (iInteractUtil != null) {
                                iInteractUtil.onNetworkInteractOver(ret, REMOVEFRIEND, response);
                                if (flags.size() == 0 && isChecked) {
                                    iInteractUtil.onNetworkInteractAllOver(0);
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, REMOVEFRIEND, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(removeFriendRequest);
    }

    /**
     * 添加员工
     *
     * @param jsonParam
     */
    public void addEmployee(JSONObject jsonParam) {
        flags.add(ADDEMPLOYEE);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        addEmployeeRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.addEmployeeUrl, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("result=" + response);
                        flags.remove(ADDEMPLOYEE);
                        int resultCode = -1;
                        try {
                            resultCode = response.getInt("code");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        //0 成功 1 账户不存在 2添加失败 3账户已被添加
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, ADDEMPLOYEE, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, ADDEMPLOYEE, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(addEmployeeRequest);
    }

    /**
     * 删除员工
     *
     * @param jsonParam
     */
    public void removeEmployee(JSONObject jsonParam) {
        flags.add(REMOVEEMPLOYEE);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        removeEmployeeRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.removeEmployeeUrl, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("result=" + response);
                        flags.remove(REMOVEEMPLOYEE);
                        int resultCode = -1;
                        try {
                            resultCode = response.getInt("code");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        //0 成功 1 账户不存在 2添加失败 3账户已被添加
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, REMOVEEMPLOYEE, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, REMOVEEMPLOYEE, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(removeEmployeeRequest);
    }

    /**
     * 获得员工指派信息
     *
     * @param jsonParam
     */
    public void getEmployeeAssigned(JSONObject jsonParam) {
        flags.add(GETEMPLOYEEASSIGNED);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        getEmployeeAssignedRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.getUserAssignUrl, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println("result=" + response);
                        flags.remove(GETEMPLOYEEASSIGNED);
                        int resultCode = -1;
                        try {
                            resultCode = response.getInt("code");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        //0 成功 1 账户不存在 2添加失败 3账户已被添加
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, GETEMPLOYEEASSIGNED, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, GETEMPLOYEEASSIGNED, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(getEmployeeAssignedRequest);
    }


    /**
     * 更新指派信息
     *
     * @param jsonParam
     */
    public void updateAssignTo(JSONObject jsonParam) {
        flags.add(UPDATEASSIGNTO);
        try {
            jsonParam.put("userid", SharedUtil.getInstance().readUserId());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        updateAssignToRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.updateAssignToUrl, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        flags.remove(UPDATEASSIGNTO);
                        int resultCode = -1;
                        try {
                            resultCode = response.getInt("code");
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        //0 成功 1 指派失败
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(resultCode, UPDATEASSIGNTO, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, UPDATEASSIGNTO, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(updateAssignToRequest);
    }


    /**
     * get order id
     *
     * @param jsonParam
     */
    public void syncGetNewOrderId(JSONObject jsonParam) {
        flags.add(GETNEWORDERID);
        try {
            JSONObject loginSp = SharedUtil.getInstance().readLoginInfo();
            String username = null;
            try {
                username = loginSp.getString("username");
                jsonParam.put("username", username);
            } catch (JSONException e) {
                e.printStackTrace();
                return;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        /**
         * {"uname":"admin2","device":
         * {"did":"SUCU-000001-ABCEF","username":"admin","password":"123456","name":"sncu"}}
         */
        syncGetNewOrderIDRequest = new JsonObjectRequest(Request.Method.POST, SystemConstant.getNewOrderID_url, jsonParam,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        flags.remove(GETNEWORDERID);
                        if (iInteractUtil != null) {
                            iInteractUtil.onNetworkInteractOver(0, GETNEWORDERID, response);
                            if (flags.size() == 0 && isChecked) {
                                iInteractUtil.onNetworkInteractAllOver(0);
                            }
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println("error=" + error.toString());
                if (error instanceof NetworkError) {
                } else if (error instanceof ServerError) {
                } else if (error instanceof AuthFailureError) {
                } else if (error instanceof ParseError) {
                } else if (error instanceof NoConnectionError) {
                } else if (error instanceof TimeoutError) {
                }
                if (iInteractUtil != null) {
                    iInteractUtil.onNetworkInteractOver(-1, GETNEWORDERID, new JSONObject());
                    if (flags.size() == 0 && isChecked) {
                        iInteractUtil.onNetworkInteractAllOver(0);
                    }
                }

            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> header = new HashMap<String, String>();
                header.put("Authorization", " Bearer " + SystemConstant.session_token);
                return header;
            }

            ;
        };
        AQApplication.getInstance().mQueue.add(syncGetNewOrderIDRequest);
    }


}
